<?php
$ip  = $name = $pwd = '';
if($_SERVER['REQUEST_METHOD'] =='POST'){
    $ip = $_POST['ip'];
    $name = $_POST['fname'];
    $pwd = $_POST['pwd'];
    $conn = new mysqli($ip,$name,$pwd);
    try{
        if(!$conn->connect_error){
            echo '连接成功';
        }else{
            echo '连接失败';
        };

    }catch (\mysql_xdevapi\Exception $e){
        echo '连接失败';
    }finally{
        echo '连接关闭';
        $conn ->close();
    }
}
//$servername = 'localhost';
//$username = 'root';
//$password = '123456';
////创建连接
//$conn = new mysqli($servername,$username,$password);
////检车连接
//if($conn->connect_error){
//    die ('连接失败'.$conn->connect_error);
//}
//echo '连接成功';
?>

<form action="" method="post">
    ip <input type="text" name = 'ip' value="<?php echo $ip; ?>">
    <br>
    帐号 <input type="text" name = 'fname' value = '<?php echo $name;?>'>
    <br>
    密码: <input type="text" name = 'pwd' value = '<?php echo $pwd;?>'>
    <br>
    <input type="submit" value='连接'>
</form>

